﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace SBS_Sprite_Sheeter
{
    public class SpriteElement
    {
        public Rectangle rect;
        public string name;

        public SpriteElement() { }
        public SpriteElement(Rectangle rect, string name)
        {
            this.rect = rect;
            this.name = name;
        }
    }

    public class SpriteSheet : IDisposable
    {
        #region Variables
        public Dictionary<string, SpriteElement> sprites = new Dictionary<string, SpriteElement>();
        public List<SpriteElement> spriteList = new List<SpriteElement>();
        public Texture2D texture;
        #endregion

        #region Constructor

        #endregion

        #region XNA Functions
        public static SpriteSheet Load(string str, string assetName, ContentManager Content)
        {
            return null;
        }

        public void Save(string str)
        {
            if (!File.Exists(str))
            {
                FileStream file = File.Create(str);
                file.Close();
            }

            Stream outStream = File.Open(str, FileMode.Open);
            StreamWriter writer = new StreamWriter(str, false, Encoding.ASCII);
            Dictionary<string, SpriteElement>.Enumerator iter = sprites.GetEnumerator();
            spriteList = new List<SpriteElement>();

            while (iter.MoveNext())
            {
                spriteList.Add(iter.Current.Value);
            }

            writer.WriteLine(this);
            outStream.Close();
        }
        #endregion

        #region IDisposable Members
        public void Dispose()
        {
            if (texture != null)
            {
                texture.Dispose();
            }
            texture = null;
        }
        #endregion
    }
}